package bdgrade;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JFormattedTextField;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Font;
import javax.swing.DropMode;
import javax.swing.SwingConstants;

import domain.Stu;
import domain.Student;
import service.Impl.StuServiceImpl;
import tools.FileTool;

import javax.swing.JSpinner;
import javax.swing.JSeparator;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.JTextArea;

public class IsOK {
	//确定是否删除界面
	private JFrame frame;
	private StuServiceImpl stuService=new StuServiceImpl();
	public static void main(String[] args) {
		int []row= {1,2,3};
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IsOK window = new IsOK(row);
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public IsOK(int []row) {
		initialize(row);
	}

	private void initialize(int []row) {
		frame = new JFrame();
		frame.getContentPane().setBackground(Color.WHITE);
		frame.setBounds(100, 100, 450, 300);
		frame.getContentPane().setLayout(null);
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frame.setResizable(false);
		frame.setVisible(true);
		
		JTextArea textArea = new JTextArea();
		textArea.setFont(new Font("Monospaced", Font.PLAIN, 20));
		textArea.setBounds(14, 13, 418, 70);
		frame.getContentPane().add(textArea);
		String str_row ="确定要删除第 ";
		for(int i=0;i<row.length;i++) {
			int index=row[i]+1;
			str_row+=index+" ";
		}
		str_row+="行吗?";
		textArea.setText(str_row);
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(0, 96, 432, 157);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JButton button_1 = new JButton("容我再考虑一下");
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				frame.dispose();
			}
		});
		button_1.setBounds(96, 61, 137, 27);
		panel.add(button_1);
		
		JButton button = new JButton("确定");
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				//开始删除数据
				//逐行删除
				List<Stu>stuList=new ArrayList<>();
				for (int r : row) {
					Stu byRow = stuService.findByRow(r);
					stuList.add(byRow);
				}
				for (Stu stu : stuList) {
					stuService.delete(stu.getID(),stu.getCourse());
				}
				frame.dispose();
			}
		});
		button.setBounds(247, 61, 63, 27);
		panel.add(button);	
	}
	
	
}
	